package com.bole.webflux.reactor;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.stream.Stream;


/**
 * @author: 叶子
 * @date: 2022/03/31 22:10
 **/
public class ReactorDemo {
    public static void main(String[] args) {
//        mono创建方式
//        Mono.empty().subscribe(System.out::println);
        Mono.just("hello mono").subscribe(System.out::println);
        //Flux创建方式 0-n 元素序列
//        Flux.just(1, 2, 3, 4, 5, 6).subscribe(System.out::println);
//        Flux.fromIterable(Arrays.asList("a","b","c","d")).subscribe(System.out::println);
//        Flux.fromArray(new String[]{"a","b","c","d"}).subscribe(System.out::println);
//        Flux.fromStream(Stream.of(1,2,3,4,5,6,7,8,9)).subscribe(System.out::println);
//        Flux.range(1,100).subscribe(System.out::println);
        /**
         * 2*0=0
         * 2*1=2
         * 2*3=3
         * ...
         * 2*10=20
         */
        Flux.generate(()->0,(i,sink)->{sink.next("2*"+i+"="+2*i);if (i==10) sink.complete();return i+1;})
                .subscribe(System.out::println);
    }
}